package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 使用预编译SQL语句执行DML操作：UPDATE
 */
public class JDBCDemo10 {
    public static void main(String[] args) {
        /**
         * 需求：根据用户id修改 用户的昵称、密码、年龄
         */
         try(Connection conn = DBUtil.getConnection();
        ) {
             String sql = "UPDATE userinfo " +
                          "SET password = ?,nickname = ?,age = ? " +
                          "WHERE id = ?";
             PreparedStatement ps = conn.prepareStatement(sql);
             ps.setString(1,"999999");
             ps.setString(2,"范大奇");
             ps.setInt(3,18);
             ps.setInt(4,6);

             int num =  ps.executeUpdate();
             System.out.println(num > 0?"修改成功":"修改失败");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
